#include <iostream>
#include <stdio.h>

#include <iostream>
#include <memory>


template <typename T>
class StackDemo
{
public:
    StackDemo(int size=100);
    ~StackDemo();

    void push(const T& node);
    void pop();
    T top();

    int size() const;
    bool empty() const;
    void clear();


private:
    T *data;
    int Top;
    int MAXSIZE;
};

template <typename T>
StackDemo<T>::StackDemo(int size):Top(-1),MAXSIZE(size)
{
    data = new T[size];
}

template <typename T>
StackDemo<T>::~StackDemo()
{
    clear();
    delete [] data;
}

template<typename T>
void StackDemo<T>::clear()
{
    while(Top != -1)
        data[Top--].~T();
}

template<typename T>
void StackDemo<T>::push(const T& value)
{
    if(Top==MAXSIZE-1)
    {
        std::cerr<<"栈满"<<std::endl;
        return;
    }
    data[++Top] = value;
}

template<typename T>
T StackDemo<T>::top()
{
    if(Top == -1){
        std::cerr<<"ERROE, stack is empty."<<std::endl;
    }

    return data[Top];
}

template<typename T>
void StackDemo<T>::pop()
{
    if(Top == -1){
        std::cerr<<"ERROE, stack is empty."<<std::endl;
        return;
    }

    Top--;
}

template<typename T>
bool StackDemo<T>::empty() const
{
    return Top==-1;
}

template<typename T>
int StackDemo<T>::size()const
{
    return Top+1;
}
int main(int argv, char**argc)
{
    printf("************  test hello zc!!!   **************\n");
    /* add test code! */

    StackDemo<int> s(10);
        for(int i = 0; i < 10; ++i)
        {
            s.push(i);
        }
        for(int j = s.size()-1 ; j >= 0; --j)
        {
            std::cout<< "node: " << s.top() <<std::endl;
            s.pop();
        }

       std::cout<<s.size();
    
    return 0;
}
